//
//  XSScrollCollectionViewController.m
//  MeiLiYiChu
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "XSScrollCollectionViewController.h"
#import "XSMain.h"
#import "XSView.h"
 XSScrollCollectionViewController * viewVC;
@interface XSScrollCollectionViewController ()

@end

@implementation XSScrollCollectionViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    XSView *view =[[XSView alloc]initWithBool:YES withString:self.navTitle];
    
    [self.view addSubview:view];
    UIButton * btn =(UIButton *)[view viewWithTag:1];
    [btn addTarget:self action:@selector(btn) forControlEvents:UIControlEventTouchUpInside];

    UIButton  *btn2 =(UIButton *)[view viewWithTag:2];

    [btn2 addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
    
    _topView =[[UIView alloc]initWithFrame:CGRectMake(0, 44, self.view.bounds.size.width, 250)];

    UIImageView * imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _topView.frame.size.width, 200)];

    [imageView sd_setImageWithURL:[NSURL URLWithString:_imageName]];
    
    [_topView addSubview:imageView];

    UILabel * lab =[[UILabel alloc]initWithFrame:CGRectMake(10, imageView.frame.origin.y+imageView.frame.size.height, imageView.frame.size.width, 50)];
    lab.numberOfLines =0;
    //请求获取到的
    lab.text =_labTitle;
    
    [_topView addSubview:lab];

    _block(_topView);
    
    
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
}
-(void)btn
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)share
{
    //跳转分享页面
}
-(void)viewWillAppear:(BOOL)animated
{
    [XSHTTPManager getScollDetailWithComplection:^(NSMutableArray *array2, NSString *next_cursor) {
        _scrollArr =array2;
        [self.collectionView reloadData];
       
    } :_url ];
    self.navigationController.navigationBarHidden =YES;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
   
    return _scrollArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    cell.contentView.backgroundColor =[UIColor whiteColor];
    
    UIImageView * imageView1 =(UIImageView *)[cell.contentView viewWithTag:cell.tag+10];
    if (imageView1==nil)
    {
        imageView1 =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width/2-10, 240)];
        imageView1.tag =cell.tag+10;
        
        [cell.contentView addSubview:imageView1];
    }
    
    UILabel * lab1 =(UILabel *)[cell.contentView viewWithTag:cell.tag +200];
    if (lab1 ==nil)
    {
        lab1 =[[UILabel alloc]initWithFrame:CGRectMake(0, 240, self.view.bounds.size.width/2-10, 50)];
        lab1.tag =cell.tag +200;
        
        lab1.font =[UIFont systemFontOfSize:14];
        lab1.numberOfLines =0;
        
        [cell.contentView addSubview:lab1];
    }
    UILabel * lab2 =(UILabel *)[cell.contentView viewWithTag:cell.tag +500];
    if (lab2 ==nil)
    {
        lab2 =[[UILabel alloc]initWithFrame:CGRectMake(0, 280, self.view.bounds.size.width/2-30, 20)];
        lab2.tag =cell.tag +500;
        
        lab2.textColor =[UIColor magentaColor];
        [cell.contentView addSubview:lab2];
    }
    
    XSMain * main =_scrollArr[indexPath.row];
    [imageView1 sd_setImageWithURL:[NSURL URLWithString:main.taobao_pic_url]];
   
    lab1.text =main.taobao_title;
    lab2.text =[NSString stringWithFormat:@"%@ %@",main.money_symbol,main.taobao_selling_price];
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
